var url = location.search;
var hashes = url.slice(url.indexOf('?') + 1).split('&');
var myJson, hash;
$(function(){
    updateData();
})
function updateData(self){
    var kid = sessionStorage.getItem("kid");
    var myJson;
    var data = {'kid': kid}
    getdata(host + "userproject/findDetailByKid", data,
        function(res){
           if(res.res.code == 40000){
                if(self == 1){
                    Common.TipTop($("#submit"), '保存成功', "-100px");
                    $('#maketip:not("#uploadtip")').empty();
                    $('#edit').html('编辑');
                    window.location.href = $().AbsUrlParse("/web/page/uploadMessage");

                }
                myJson = res.res.data;
           } else {
                Common.TipTop($("#submit"), res.res.msg, "-100px");
                return false;
           }
        }
    )
    if(myJson.auditState == "审核失败"){
        $('.auditReasonBox').show();
        $('#auditReason').html(myJson.auditReason)
    } else {
        $('.auditReasonBox').hide();
    }
    $('body input[type="text"],body input[type="email"],body textarea,.select-sex input[name="sex"],#involved-industry input').attr('disabled',true);
    $('#file').attr('disabled', true);
    $('#checkbox-id').attr('checked',true);
    if(myJson.auditState == "审核通过"){
        $('#check-result').css('color','#2aaa1f');
    }
    if(myJson.ruleState == "初赛"){
        $('#check-result').html(myJson.auditState);
    } else {
        $('#check-result').html(myJson.auditStateSecond);
    }
    $('#principal').val(myJson.proposer);
    $('#proposer-phone').val(myJson.declarationMobile);
    $('#proposer-email').val(myJson.proposerEmail);
    $('#project-name').val(myJson.declareProject);
    $('#declare-contact').val(myJson.declarationContact);
    $('#declare-contact-phone').val(myJson.proposerMobile);
    $('#declare-content').val(myJson.declarationMemo);
    $('#declare-case').val(myJson.fundInput);
    if(myJson.isRegEnterprice != ""){
        $('#whether-register').find("option[value="+ myJson.isRegEnterprice + "]").prop("selected",true);
    }
    if(myJson.isRegEnterprice == "是"){
        $('#location-name').val(myJson.enterpriceName);
        $('#location-name').attr("disabled", true);
        $('#location-time').val('type');
        var date = changeDateFormatArt(myJson.enterpriceRegtime);
        if(IsPC()){
            $('.form_datetime').val(date);
            $('.pc-time').show();
            $('.phone-time').hide();
            // 点击事件框触发事件
            $('.form_datetime').datetimepicker({
                minView: "month", //选择日期后，不会再跳转去选择时分秒
                language:  'zh-CN',
                format: 'yyyy-mm-dd',
                autoclose: true,
　　            todayHighlight: true,
                todayBtn: true
            });
        } else {
            $('#time-format').val(date);
            $('.pc-time').hide();
            $('.phone-time').show();
            $("#time-format").datetimePicker({
                title: '时间选择',
                yearSplit: '-',
                monthSplit: '-',
                times: function () {
                },
                onChange: function (picker, values, displayValues) {
                    timeValues = values.join('-')
                }
            });
        }
        $('#location-place').val(myJson.enterpriceRegaddress);
    } else {
        $('.hiddenDiv').hide();
    }
    if(myJson.parkUnit != ""){
        $('#proposer-garden').find("option[value="+ myJson.parkUnit + "]").prop("selected",true);
    }
    if(myJson.proposerSex == "男"){
        $(".select-sex input[name='sex']").eq(0).attr("checked","checked");
    } else {
        $(".select-sex input[name='sex']").eq(1).attr("checked","checked");
    }
    $("#sex input[value=" + myJson.proposerSex + "]").parent().find('.fbc_optionSvg').css('color','#2D8FD9');
    $("#sex input[value!=" + myJson.proposerSex + "]").parent().find('.fbc_optionSvg').css('color','#C5C5C6');
    var checkVariable = true;
    if(myJson.industryOwned != ""){
        $("#involved-industry input[value=" + '其他' + "]").attr("checked","checked");
        $("#involved-industry input").each(function () {
            if($(this).val() != myJson.industryOwned){
                $("#involved-industry input[value=" + '其他' + "]").parent().find('.fbc_optionSvg').css('color','#2D8FD9');
                $("#involved-industry input[value!=" + '其他' + "]").parent().find('.fbc_optionSvg').css('color','#C5C5C6');
                $('#showOther').show();
                $('#other').val(myJson.industryOwned);
            } else {
                checkVariable = false;
            }
        });
        if(checkVariable == false){
            $('#other').val('');
            $('#showOther').hide();
            $("#involved-industry input[value=" + myJson.industryOwned + "]").parent().find('.fbc_optionSvg').css('color','#2D8FD9');
            $("#involved-industry input[value!=" + myJson.industryOwned + "]").parent().find('.fbc_optionSvg').css('color','#C5C5C6')
        }
    }

    $('#location-reality-place').val(myJson.actualAddress);
    if(myJson.attachmentPath != ""){
    		var attachmentPath = myJson.attachmentPath;
    		var attachmentPath = attachmentPath.split(',');
    		for (var i = 0; i < attachmentPath.length; i++) {
    			var span = '<div style="border: 1px dashed #d3d3d3;padding: 5px;margin-top:10px;"><span class="uploadInfo" url='+ attachmentPath[i] +' style="word-wrap:break-word;"><font>' + '已上传：' + attachmentPath[i] + '</font></span><div class="deleteFile" style="cursor: pointer;">取消上传</div></div>';
    			$('#maketip').append(span);
        }
    }
    if(myJson.videoPath != ''){
        $('#bd-link').val(myJson.videoPath);
    }
    kid = myJson.kid;
}
$(document).on("click", "#edit", function () {
    var content = $(this).html();
    if(content == "编辑"){
        $(this).html('正在编辑');
        $('body input[type="text"],body input[type="email"],body textarea').attr('disabled',false);
        $('#file').attr('disabled', false);
        var delFilePath = [];
        var delDom = $('#maketip .uploadInfo');
        for (var i = 0; i < delDom.length; i++) {
            delFilePath[i] = $('#maketip .uploadInfo').eq(i).attr('url');
        }
        attentmentPath = delFilePath.join(',');
    } else {
        $(this).html('编辑');
        $('body input[type="text"],body input[type="email"],body textarea').attr('disabled',true);
        $('#file').attr('disabled', true);
    }
})
